package com.knowif.backend.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.knowif.enumInfo.UserEnum;
import com.knowif.pojo.TUser;
import com.knowif.pojo.TUserExample;
import com.knowif.service.Manager_service;
import com.knowif.system.model.RestBean;
import com.knowif.util.commonUtil.StringUtil;

@Service
public class ManagerService {
	
	private Manager_service manager_service;
	
	
	/**
	 * @author: xingyao 
	 * @Description:  用户登入功能
	 * @param tUser
	 * @return
	 */
	public RestBean<?> login(String username,String password){
		if(StringUtil.isEmpty(username) || StringUtil.isEmpty(password)){
			return RestBean.buildError("请输入用户名或者密码");
		}
		TUserExample tUserExample = new TUserExample();
		tUserExample.createCriteria().andUsernameEqualTo(username)
			.andPasswordEqualTo(password)
			.andUserTypeEqualTo(UserEnum.MANAGER.getNumber());
		List<TUser> managers = manager_service.selectManager(tUserExample);
		if(managers == null || managers.isEmpty()){
			return RestBean.buildError("没有找到该名管理员");
		}
		return RestBean.buildSuccess(managers);
	}
	
}
